﻿using System;
using System.Collections;
using System.Collections.Generic;
using OWL.Rendering.HRP;
using UnityEditor;
using UnityEngine;
using Yoozoo.HRP.Runtime;

[CustomEditor( typeof(MapNavmeshData))]
public class MapNavmeshDataInspector : Editor
{
    private MapNavmeshData mapData;
    private void OnEnable()
    {
        mapData = target as MapNavmeshData;
    }

    public override void OnInspectorGUI()
    {
        if (GUILayout.Button("一键搜索静态"))
        {
            CollectMesh();
        }
        base.OnInspectorGUI();
    }

    private void CollectMesh()
    {
        var staticRoot = mapData.transform.Find("StaticRoot");
        if (staticRoot == null)
        {
            UnityEngine.Debug.LogError("请先创建StaticRoot");
            return;
        }
        var meshFilters = staticRoot.GetComponentsInChildren<MeshFilter>();
        mapData.meshList = new List<MeshFilter>();
        mapData.meshList.Clear();
        foreach (var meshFilter in meshFilters)
        {
            mapData.meshList.Add(meshFilter);
        }
    }
}
